/*
	StargateWW for GarrysMod10
	Copyright (C) 2008 Prefanatic

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

--################# Set the spawn possitions @Prefanatic
function spawnPos(ply, command, args)
	if (ply:IsAdmin()) then
		if (table.concat(args, " ") == "villager") then
			local villagerPos = ply:GetPos()
			file.Write("StargateWW/Spawns/" .. game.GetMap() .. "_villager.txt",tostring(villagerPos))
			Msg("villager spawn position set.\n")
		elseif (table.concat(args, " ") == "atlantis") then
		local atlantisPos = ply:GetPos()
			file.Write("StargateWW/Spawns/" .. game.GetMap() .. "_atlantis.txt",tostring(atlantisPos))
			Msg("atlantis spawn position set.\n")
		elseif (table.concat(args, " ") == "wraith") then
			local wraithPos = ply:GetPos()
			file.Write("StargateWW/Spawns/" .. game.GetMap() .. "_wraith.txt",tostring(wraithPos))
			Msg("wraith spawn position set.\n")
		else
			Msg("That is not an available Team.\n")
		end
		return ""
	end
	return ""
end
concommand.Add("setspawn", spawnPos)

--################# Loads up the spawns for quick access when spawning @Prefanatic
function setspawnPos(ply)
		if (ply:Team() == 1) then
			if file.Exists("StargateWW/Spawns/" .. game.GetMap() .. "_villager.txt") then
				local tempvillagerPos = file.Read("StargateWW/Spawns/" .. game.GetMap() .. "_villager.txt")
				tempvillagerPos = (string.Explode(" " ,tempvillagerPos))
				ply:SetPos(Vector(tonumber(tempvillagerPos[1]),tonumber(tempvillagerPos[2]),tonumber(tempvillagerPos[3])))
			end
			return ""
		elseif (ply:Team() == 10 or ply:Team() == 11 or ply:Team() == 12 or ply:Team() == 13) then
			if file.Exists("StargateWW/Spawns/" .. game.GetMap() .. "_atlantis.txt") then
				local tempatlantisPos = file.Read("StargateWW/Spawns/" .. game.GetMap() .. "_atlantis.txt")
				tempatlantisPos = (string.Explode(" " ,tempatlantisPos))
				ply:SetPos(Vector(tonumber(tempatlantisPos[1]),tonumber(tempatlantisPos[2]),tonumber(tempatlantisPos[3])))
			end
			return ""
		elseif (ply:Team() == 20 or ply:Team() == 21 or ply:Team() == 22 or ply:Team() == 23) then
			if file.Exists("StargateWW/Spawns/" .. game.GetMap() .. "_wraith.txt") then
				local tempwraithPos = file.Read("StargateWW/Spawns/" .. game.GetMap() .. "_wraith.txt")
				tempwraithPos = (string.Explode(" " ,tempwraithPos))
				ply:SetPos(Vector(tonumber(tempwraithPos[1]),tonumber(tempwraithPos[2]),tonumber(tempwraithPos[3])))
			end
			return ""
		end
		return ""
end

--################# Initialize spawn possitions @Prefanatic
function initspawnPos()
		if file.Exists("StargateWW/Spawns/" .. game.GetMap() .. "_villager.txt") then
			local tempvillagerPos = file.Read("StargateWW/Spawns/" .. game.GetMap() .. "_villager.txt")
			tempvillagerPos = (string.Explode(" " ,tempvillagerPos))
		end
		if file.Exists("StargateWW/Spawns/" .. game.GetMap() .. "_atlantis.txt") then
			local tempatlantisPos = file.Read("StargateWW/Spawns/" .. game.GetMap() .. "_atlantis.txt")
			tempatlantisPos = (string.Explode(" " ,tempatlantisPos))
		end
		if file.Exists("StargateWW/Spawns/" .. game.GetMap() .. "_wraith.txt") then
			local tempwraithPos = file.Read("StargateWW/Spawns/" .. game.GetMap() .. "_wraith.txt")
			tempwraithPos = (string.Explode(" " ,tempwraithPos))
		end
end